
import {
    requestUtil,
} from '../../utils/requestUtil.js';
// pages/orderp/orderp.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    date:null,
    time:null,
    name:null,
    adress:null,
    price:0,
    type:null,
    phone:null,
  },

  bindDateChange: function(e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      date: e.detail.value
    })
  },
  bindTimeChange: function(e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      time: e.detail.value
    })
  },
  jumpa(){
      wx.navigateTo({
        url: '/pages/address/address',
      })
  },
  async yuyue(){
      if(!this.data.adress) {
        return wx.showToast({
            icon:'none',
          title: '请选择服务地址',
        })
      }
      if(!this.data.date) {
        return wx.showToast({
            icon:'none',
          title: '请选择服务日期',
        })
      }
      if(!this.data.time) {
        return wx.showToast({
            icon:'none',
          title: '请选择服务时间',
        })
      }
      const result = await requestUtil({url: '/fuwuyuyue/add',
      data:{
        dizhi:this.data.adress,
        fuwujiage:this.data.price,
        fuwuleixing:this.data.type,
        fuwumingcheng:this.data.name,
        yuyueshijian:this.data.date+" "+this.data.time+":00",
        shoujihaoma:this.data.phone,
      },method:"POST"});
        if(result.code==0) {
            wx.showToast({
                icon:'success',
              title: '下单成功',
              success:function(){
                  console.log('snddndn')
              }
            })
            wx.navigateTo({
                url: '/pages/pay/index?name='+this.data.name+'&time='+this.data.date+" "+this.data.time+":00"+'&price='+this.data.price+'&orderId='+result.data,
              })
        }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setData({
        name:options.name,
        price:options.price,
        type:options.type
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    if(wx.getStorageSync('address')) {
        var as = wx.getStorageSync('address')
      console.log(as,'dndndnd')
        this.setData({
            adress:as[0].address,
            phone:as[0].telNumber
        })
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})